/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.wanhai.itm.validator;

import org.zkoss.bind.ValidationContext;
import org.zkoss.bind.validator.AbstractValidator;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Textbox;

/**
 *
 * @author m2434
 */
public class NoEmptyValidator extends AbstractValidator{
    public void validate(ValidationContext ctx) {
        Object var = ctx.getProperty().getValue();
        Textbox tb =  (Textbox) ctx.getBindContext().getComponent();
        
        System.out.println("~~~~~~~ in NoEmptyValidator ~~~~~");
        System.out.println("~~~~~~~ tb ~~~~~ = "+tb.getId());
        
        if(var.equals("")){
            tb.setSclass("error-textbox");
            System.out.println("~~~~~~~invalid~~~~~");
            addInvalidMessage(ctx, "no empty, please!");
//            ctx.setInvalid();
            Clients.showNotification("no empty, please!","error",null,"top_right",2000);
        }else{
            tb.setSclass("");
        }
    }
}
